﻿package view.task
{
    import com.core.*;
    import com.sh.game.util.*;
    import flash.events.*;
    import flash.utils.*;
    import manager.*;
    import plugin.ybstore.consts.*;

    public class TaskCopyCtrl extends TaskCopyUI
    {
        private var time:int = 0;
        private var timeDis:int = 0;

        public function TaskCopyCtrl()
        {
            txt_desc.addEventListener(TextEvent.LINK, this.doLink);
            txt_buy.addEventListener(TextEvent.LINK, this.doBuy);
            return;
        }// end function

        protected function doLink(event:TextEvent) : void
        {
            var _loc_2:Array = null;
            var _loc_3:Array = null;
            _loc_2 = event.text.split("&");
            switch(int(_loc_2[0]))
            {
                case 1:
                {
                    _loc_3 = _loc_2[1].split("#");
                    ModelProxy.change("zone", "autoMove", {x:_loc_3[1], y:_loc_3[2], tostageid:_loc_3[0], onhorse:true});
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

        protected function doBuy(event:TextEvent) : void
        {
            PluginManager.instance.sendToServer("store", CMDStore.GetPrice, event.text);
            return;
        }// end function

        public function setShow(param1:Object) : void
        {
            var _loc_3:Object = null;
            var _loc_2:* = ConfigDictionary.data.instance;
            switch(int(param1.index))
            {
                case 1:
                {
                    _loc_3 = _loc_2[1070];
                    break;
                }
                case 2:
                {
                    _loc_3 = _loc_2[1035];
                    break;
                }
                case 3:
                {
                    _loc_3 = _loc_2[1027];
                    break;
                }
                default:
                {
                    break;
                }
            }
            txt_desc.text = _loc_3.tips;
            var _loc_4:* = int((ModelProxy.getValue("data", "servertime") + Number(getTimer())) / 1000);
            var _loc_5:* = new Date();
            new Date().setTime(_loc_4 * 1000);
            var _loc_6:* = new Date(_loc_5.fullYear, _loc_5.month, _loc_5.date, param1.endHour, param1.endMin, 0, 0);
            this.timeDis = (_loc_6.getTime() - _loc_5.getTime()) / 1000;
            if (this.timeDis > 0)
            {
                this.time = setInterval(this.doTime, 1000);
            }
            else
            {
                ModelProxy.change("tasktrack", "closeActive", null);
            }
            txt_buy.text = _loc_3.buy;
            return;
        }// end function

        private function doTime() : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this.timeDis - 1;
            _loc_2.timeDis = _loc_3;
            var _loc_1:* = this.timeDis > 30 ? ("00ff00") : ("ff0000");
            if (this.timeDis < 0)
            {
                clearInterval(this.time);
                this.time = 0;
                ModelProxy.change("tasktrack", "closeActive", null);
                return;
            }
            txt_time.text = "<font color=\'#ffcc00\'>剩余时间：</font><font color=\'#" + _loc_1 + "\'>" + TimeDataFormatUtil.getLeftTime(this.timeDis) + "</font>";
            return;
        }// end function

    }
}
